home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 February: Technology Seed / Mac Tech Seed Feb '97.toast / ODF Release 3 / ODFDev / Container / Sources / Frame.cpp < prev    next >
Encoding:
Text File  |  1996-12-16  |  23.0 KB  |  724 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                Frame.cpp
  4. //    Release Version:    $ ODF 3 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "Container.hpp"
  11.  
  12. #ifndef FRAME_H
  13. #include "Frame.h"
  14. #endif
  15.  
  16. #ifndef PART_H
  17. #include "Part.h"
  18. #endif
  19.  
  20. #ifndef DEFINES_K
  21. #include "Defines.k"
  22. #endif
  23.  
  24. #ifndef COMMANDS_H
  25. #include "Commands.h"
  26. #endif
  27.  
  28. #ifndef SELECT_H
  29. #include "Select.h"
  30. #endif
  31.  
  32. #ifndef PROXY_H
  33. #include "Proxy.h"
  34. #endif
  35.  
  36. #ifndef VIEW_H
  37. #include "View.h"
  38. #endif
  39.  
  40. #ifndef CONTENT_H
  41. #include "Content.h"
  42. #endif
  43.  
  44. // ----- Framework Layer -----
  45.  
  46. #ifndef FWCONTXT_H
  47. #include "FWContxt.h"
  48. #endif
  49.  
  50. #ifndef FWUTIL_H
  51. #include "FWUtil.h"
  52. #endif
  53.  
  54. #ifndef FWPRESEN_H
  55. #include "FWPresen.h"
  56. #endif
  57.  
  58. #ifndef FWSCROLR_H
  59. #include "FWScrolr.h"
  60. #endif
  61.  
  62. #ifndef FWSCLBAR_H
  63. #include "FWSclBar.h"
  64. #endif
  65.  
  66. #ifndef FWGROWBX_H
  67. #include "FWGrowBx.h"
  68. #endif
  69.  
  70. #ifndef FWFCTCLP_H
  71. #include "FWFctClp.h"
  72. #endif
  73.  
  74. #ifndef FWSUUTIL_H
  75. #include "FWSUUtil.h"
  76. #endif
  77.  
  78. #ifndef FWSUSINK_H
  79. #include "FWSUSink.h"
  80. #endif
  81.  
  82. // ----- OS Layer -----
  83.  
  84. #ifndef FWMENU_H
  85. #include "FWMenu.h"
  86. #endif
  87.  
  88. #ifndef FWRECSHP_H
  89. #include "FWRecShp.h"
  90. #endif
  91.  
  92. #ifndef FWODGEOM_H
  93. #include "FWODGeom.h"
  94. #endif
  95.  
  96. #ifndef FWRGNSHP_H
  97. #include "FWRgnShp.h"
  98. #endif
  99.  
  100. #ifndef FWGC_H
  101. #include "FWGC.h"
  102. #endif
  103.  
  104. // ----- OpenDoc Includes -----
  105.  
  106. #ifndef SOM_Module_OpenDoc_Commands_defined
  107. #include <CmdDefs.xh>
  108. #endif
  109.  
  110. #ifndef SOM_Module_OpenDoc_StdProps_defined
  111. #include <StdProps.xh>
  112. #endif
  113.  
  114. #ifndef SOM_ODSession_xh
  115. #include <ODSessn.xh>
  116. #endif
  117.  
  118. #ifndef SOM_ODDispatcher_xh
  119. #include <Disptch.xh>
  120. #endif
  121.  
  122. //========================================================================================
  123. // Runtime Information
  124. //========================================================================================
  125.  
  126. #ifdef FW_BUILD_MAC
  127. #pragma segment odfcontainer
  128. #endif
  129.  
  130. FW_DEFINE_CLASS_M4(CContainerFrame, FW_CEmbeddingFrame, FW_MDraggableFrame, FW_MDroppableFrame, FW_MContainingPropertiesFrame)
  131. FW_DEFINE_AUTO(CContainerFrame)
  132.  
  133. //========================================================================================
  134. // CContainerFrame
  135. //========================================================================================
  136.  
  137. //----------------------------------------------------------------------------------------
  138. // CContainerFrame::CContainerFrame
  139. //----------------------------------------------------------------------------------------
  140.  
  141. CContainerFrame::CContainerFrame(Environment* ev, 
  142.                                 ODFrame* odFrame, 
  143.                                 FW_CPresentation* presentation, 
  144.                                 CContainerPart* part) :
  145.     FW_CEmbeddingFrame(ev, odFrame, presentation, part),
  146.     FW_MDraggableFrame(ev, this),
  147.     FW_MDroppableFrame(ev, this),
  148.     fContainerPart(part),
  149.     fSelection((CContainerSelection*)GetPresentation(ev)->GetSelection(ev)),
  150.     fZoomFactor(FW_kFixedPos1)
  151. {    
  152.     FW_END_CONSTRUCTOR
  153. }
  154.  
  155. //----------------------------------------------------------------------------------------
  156. // CContainerFrame::~CContainerFrame
  157. //----------------------------------------------------------------------------------------
  158.  
  159. CContainerFrame::~CContainerFrame()
  160. {
  161.     FW_START_DESTRUCTOR
  162. }
  163.  
  164. //----------------------------------------------------------------------------------------
  165. //    CContainerFrame::DoAdjustMenus
  166. //----------------------------------------------------------------------------------------
  167.  
  168. FW_Handled CContainerFrame::DoAdjustMenus(Environment* ev, FW_CMenuBar* menuBar, FW_Boolean hasMenuFocus, FW_Boolean isRoot)
  169. {
  170. FW_UNUSED(isRoot);
  171.     // ----- Edit Menu -----
  172.     if (hasMenuFocus)
  173.     {
  174.         menuBar->EnableCommand(ev, kODCommandPaste, HasPropertyOnClipboard(ev, kODPropContents, NULL)); // we don't care about the type
  175.         
  176.         ODTypeToken viewType = 0;
  177.         if (fSelection->Count() == 1)
  178.         {
  179.             CProxy* proxy = fSelection->GetFirstSelectedProxy();
  180.             FW_ASSERT(proxy);    
  181.             viewType = proxy->GetViewAs();
  182.         }
  183.         else if (fSelection->Count() == 0)
  184.         {
  185.             viewType = GetPresentation(ev)->GetDefaultEmbeddedFrameViewType(ev);
  186.         }
  187.         
  188.         menuBar->EnableAndCheckCommand(ev, cAsFrame, TRUE, viewType == FW_CPart::fgViewAsFrameToken);
  189.         menuBar->EnableAndCheckCommand(ev, cAsLargeIcon, TRUE, viewType == FW_CPart::fgViewAsLargeIconToken);
  190.         menuBar->EnableAndCheckCommand(ev, cAsSmallIcon, TRUE, viewType == FW_CPart::fgViewAsSmallIconToken);
  191.         menuBar->EnableAndCheckCommand(ev, cAsThumbnail, TRUE, viewType == FW_CPart::fgViewAsThumbnailToken);
  192.         
  193.         menuBar->EnableAndCheckCommand(ev, cZoom50, TRUE, fZoomFactor == FW_DoubleToFixed(.5));
  194.         menuBar->EnableAndCheckCommand(ev, cZoom100, TRUE, fZoomFactor == FW_kFixedPos1);
  195.         menuBar->EnableAndCheckCommand(ev, cZoom200, TRUE, fZoomFactor == FW_IntToFixed(2));
  196.     }
  197.     
  198.     return FW_kNotHandled;
  199. }
  200.  
  201. //----------------------------------------------------------------------------------------
  202. //    CContainerFrame::ChangeZoomFactor
  203. //----------------------------------------------------------------------------------------
  204.  
  205. void CContainerFrame::ChangeZoomFactor(Environment* ev, FW_Fixed zoomFactor)
  206. {
  207.     fZoomFactor = zoomFactor;
  208.  
  209.     AdjustContentViewSize(ev, FW_kDontRedraw);
  210.  
  211.     FW_ASSERT(GetScroller(ev));
  212.     GetScroller(ev)->ScaleBy(ev, FW_CPoint(zoomFactor, zoomFactor));    // Will invalidate
  213. }
  214.  
  215. //----------------------------------------------------------------------------------------
  216. //    CContainerFrame::DoMenu
  217. //----------------------------------------------------------------------------------------
  218.  
  219. FW_Handled CContainerFrame::DoMenu(Environment* ev, const FW_CMenuEvent& theMenuEvent)
  220. {
  221.     FW_Handled handled = FW_kHandled;
  222.     
  223.     ODCommandID commandID = theMenuEvent.GetCommandID(ev);
  224.     switch (commandID)
  225.     {
  226.         case cZoom50:
  227.             if (fZoomFactor != FW_DoubleToFixed(0.5))
  228.                 ChangeZoomFactor(ev, FW_DoubleToFixed(0.5));
  229.             break;
  230.         case cZoom100:
  231.             if (fZoomFactor != FW_kFixedPos1)
  232.                 ChangeZoomFactor(ev, FW_kFixedPos1);
  233.             break;
  234.         case cZoom200:
  235.             if (fZoomFactor != FW_IntToFixed(2))
  236.                 ChangeZoomFactor(ev, FW_IntToFixed(2));
  237.             break;
  238.                     
  239.         case cAsFrame:
  240.             ChangeEmbeddedViewType(ev, FW_CPart::fgViewAsFrameToken);
  241.             break;
  242.         case cAsLargeIcon:
  243.             ChangeEmbeddedViewType(ev, FW_CPart::fgViewAsLargeIconToken);
  244.             break;
  245.         case cAsSmallIcon:
  246.             ChangeEmbeddedViewType(ev, FW_CPart::fgViewAsSmallIconToken);
  247.             break;
  248.         case cAsThumbnail:
  249.             ChangeEmbeddedViewType(ev, FW_CPart::fgViewAsThumbnailToken);
  250.             break;
  251.             
  252.         default:
  253.             handled = FW_kNotHandled;
  254.     }
  255.     
  256.     return handled;
  257. }
  258.  
  259. //----------------------------------------------------------------------------------------
  260. //    CContainerFrame::ChangeEmbeddedViewType
  261. //----------------------------------------------------------------------------------------
  262.  
  263. void CContainerFrame::ChangeEmbeddedViewType(Environment* ev, ODTypeToken viewAs)
  264. {
  265.     GetPresentation(ev)->SetDefaultEmbeddedFrameViewType(ev, viewAs);
  266.     
  267.     if (fSelection->Count() != 0)
  268.     {
  269.         FW_CCommand* command = FW_NEW(CViewAsCommand, (ev, fContainerPart, this, fSelection, viewAs));
  270.         command->Execute(ev);
  271.     }
  272. }
  273.  
  274. //----------------------------------------------------------------------------------------
  275. //    CContainerFrame::NewClipboardCommand
  276. //----------------------------------------------------------------------------------------
  277.  
  278. FW_CClipboardCommand* CContainerFrame::NewClipboardCommand(Environment* ev, ODCommandID commandID)
  279. {
  280.     return FW_NEW(CClipboardCommand, (ev, commandID, fContainerPart, this, fSelection, FW_kCanUndo));
  281. }
  282.  
  283. //----------------------------------------------------------------------------------------
  284. //    CContainerFrame::NewInsertCommand
  285. //----------------------------------------------------------------------------------------
  286.  
  287. FW_CInsertCommand* CContainerFrame::NewInsertCommand(Environment* ev, const FW_PFileSpecification& fileSpec)
  288. {
  289.     return FW_NEW(CInsertCommand, (ev, this, fileSpec, fSelection, FW_kCanUndo));
  290. }
  291.  
  292. //----------------------------------------------------------------------------------------
  293. //    CContainerFrame::DoActivateEvent
  294. //----------------------------------------------------------------------------------------
  295.  
  296. void CContainerFrame::DoActivateEvent(Environment* ev, const FW_CActivateEvent& theActivateEvent)
  297. {
  298. FW_UNUSED(theActivateEvent);
  299.  
  300.     if (HasSelectionFocus(ev))
  301.         fSelection->InvalidateSelectionHandles(ev, this);
  302. }
  303.  
  304. //----------------------------------------------------------------------------------------
  305. //    CContainerFrame::CanAcceptDrop
  306. //----------------------------------------------------------------------------------------
  307.  
  308. ODDragResult CContainerFrame::CanAcceptDrop(Environment* ev, ODDragItemIterator* dragInfo)
  309. {
  310. FW_UNUSED(ev);
  311. FW_UNUSED(dragInfo);
  312.     return TRUE;
  313. }
  314.  
  315. //----------------------------------------------------------------------------------------
  316. //    CContainerFrame::AdjustZoomedWindowSize
  317. //----------------------------------------------------------------------------------------
  318.  
  319. void CContainerFrame::AdjustZoomedWindowSize(Environment* ev, FW_CPoint& proposedSize)
  320. {
  321. FW_UNUSED(ev);
  322.     proposedSize = fContainerPart->GetDrawingSize();
  323.     proposedSize.x *= fZoomFactor;
  324.     proposedSize.y *= fZoomFactor;
  325.  
  326.     FW_CPoint sbSize = FW_CScrollBar::GetDefaultScrollBarSize();
  327.  
  328.     proposedSize.x += sbSize.x + FW_IntToFixed(3);    // I want to leave a little space around
  329.     proposedSize.y += sbSize.y + FW_IntToFixed(3);
  330. }
  331.  
  332. //----------------------------------------------------------------------------------------
  333. //    CContainerFrame::AdjustWindowGrowLimits
  334. //----------------------------------------------------------------------------------------
  335.  
  336. void CContainerFrame::AdjustWindowGrowLimits(Environment* ev, FW_CPoint& minSize, FW_CPoint& maxSize)
  337. {
  338. FW_UNUSED(ev);
  339. FW_UNUSED(maxSize);
  340.     FW_CPoint sbSize = FW_CScrollBar::GetDefaultScrollBarSize();
  341.  
  342.     minSize.x = FW_IntToFixed(72) + sbSize.x;
  343.     minSize.y = FW_IntToFixed(72) + sbSize.y;
  344. }
  345.  
  346. //----------------------------------------------------------------------------------------
  347. //    CContainerFrame::ExternalizeProperties
  348. //----------------------------------------------------------------------------------------
  349.  
  350. void CContainerFrame::ExternalizeProperties(Environment* ev, ODStorageUnit* su)
  351. {
  352.     ::FW_SUAddPropValue(ev, su, kBackgroundColorProp, kBackgroundColorValue);
  353.     
  354.     FW_PStorageUnitSink suSink(ev, su, kBackgroundColorProp, kBackgroundColorValue);
  355.     FW_CWritableStream stream(suSink);
  356.     
  357.     stream << fContainerPart->GetBackgroundColor();
  358. }
  359.  
  360. //----------------------------------------------------------------------------------------
  361. //    CContainerFrame::GeometryChanged
  362. //----------------------------------------------------------------------------------------
  363. //    the geometry (clip shape, external or Internal transform) of one of my facet or one of my
  364. //    embedding facet as changed
  365.  
  366. void CContainerFrame::GeometryChanged(Environment* ev,
  367.                                 ODFacet* odFacet,
  368.                                 FW_Boolean clipShapeChanged,
  369.                                 FW_Boolean externalTransformChanged)
  370. {
  371.     FW_CEmbeddingFrame::GeometryChanged(ev, odFacet, clipShapeChanged, externalTransformChanged);
  372.     
  373.     FW_CFacetClipper facetClipper;
  374.     facetClipper.ClipEmbeddedFacets(ev, this, odFacet, NULL);
  375. }
  376.  
  377. //----------------------------------------------------------------------------------------
  378. //    CContainerFrame::PostCreateViewFromStream
  379. //----------------------------------------------------------------------------------------
  380. // PostCreateViewFromStream is called after subviews are created from resources.  
  381. // Add code which cannot be handled by current resource types.
  382.  
  383. void CContainerFrame::PostCreateViewFromStream(Environment* ev)
  384. {
  385.     // ----- Remove the grow-box and scroll-bars from non-root (i.e. embedded) frames
  386.     //        ("delete" will also remove a view from the list of subviews for that frame)
  387.     if (IsRoot(ev) == false) 
  388.     {
  389.         // Remove the GrowBox 
  390.         FW_CView* growBox = FindViewByID(ev, kGrowBoxID);
  391.         FW_ASSERT(growBox);
  392.         delete growBox;    
  393.     
  394.         // Remove the scroll-bars from the scroller and then delete them
  395.         FW_CScrollBarScroller* scroller = FW_DYNAMIC_CAST(FW_CScrollBarScroller, GetScroller(ev));
  396.         FW_ASSERT(scroller);
  397.         FW_CScrollBar* hSB = scroller->GetScrollBar(ev, FW_kHorizontal);
  398.         FW_CScrollBar* vSB = scroller->GetScrollBar(ev, FW_kVertical);
  399.         
  400.         scroller->RemoveScrollBar(ev, FW_kHorizontal);
  401.         scroller->RemoveScrollBar(ev, FW_kVertical);
  402.         
  403.         delete hSB;
  404.         delete vSB;
  405.     }
  406.         
  407.     // WARNING: Make sure that classes created from resources won't be dead-stripped
  408.     FW_DO_NOT_DEAD_STRIP(FW_CGrowBox);
  409.     FW_DO_NOT_DEAD_STRIP(FW_CScrollBarScroller);
  410.     FW_DO_NOT_DEAD_STRIP(FW_CScrollBar);    
  411. }
  412.  
  413. //----------------------------------------------------------------------------------------
  414. // CContainerFrame::CreateSubViews
  415. //----------------------------------------------------------------------------------------
  416. #if 0
  417. // NOTE: This method is not used by default because views are created from resources.
  418. //         It was left to show how to create views by program instead of using resources. 
  419.     
  420. void CContainerFrame::CreateSubViews(Environment* ev)
  421. {        
  422.     FW_CRect frameRect = GetBounds(ev);    
  423.     FW_CRect contentRect = GetContentRect(ev);
  424.  
  425.     FW_CPoint drawingSize = fContainerPart->GetDrawingSize();
  426.     
  427.     // ----- Create the content view -----
  428.     FW_CRect drawViewBounds(contentRect);
  429.     if (drawViewBounds.Width() > drawingSize.x)
  430.         drawViewBounds.right = drawViewBounds.left + drawingSize.x;
  431.     if (drawViewBounds.Height() > drawingSize.y)
  432.         drawViewBounds.bottom = drawViewBounds.top + drawingSize.y;
  433.         
  434.     CContainerView* contentView = new CContainerView(ev, this, drawViewBounds, drawingSize, fContainerPart);
  435.     contentView->BecomeContentView(ev);
  436.     
  437.     FW_CScrollBar* vertSB = NULL;
  438.     FW_CScrollBar* horzSB = NULL;
  439.     // ----- Create scroll bars and grow box in root frame only -----
  440.     if (IsRoot(ev))
  441.     {    
  442.         // ----- Create the vertical scroll bar
  443.         FW_CRect vertSbRect(contentRect.right, frameRect.top - FW_kFixedPos1, 
  444.                         frameRect.right + FW_kFixedPos1, contentRect.bottom + FW_kFixedPos1);
  445.         vertSB = FW_NEW(FW_CScrollBar, (ev, this, 0, vertSbRect));
  446.         
  447.         // ----- Create the horizontal scroll bar
  448.         FW_CRect horzSbRect(frameRect.left - FW_kFixedPos1, contentRect.bottom, 
  449.                     contentRect.right + FW_kFixedPos1, frameRect.bottom + FW_kFixedPos1);
  450.         horzSB = FW_NEW(FW_CScrollBar, (ev, this, 0, horzSbRect));
  451.         
  452.         // ----- Create the GrowBox gadget
  453.         FW_CGrowBox* growBox = new FW_CGrowBox(ev, this, 0, contentRect.BotRight());
  454.     }
  455.  
  456.     // ----- add a scroller to the Frame -----
  457.     FW_CScroller* scroller = FW_NEW(FW_CScrollBarScroller, (ev, this, horzSB, vertSB));
  458.     AdoptScroller(ev, scroller);
  459. }
  460. #endif
  461.  
  462. //----------------------------------------------------------------------------------------
  463. // CContainerFrame::GetContentRect
  464. //----------------------------------------------------------------------------------------
  465.  
  466. FW_CRect CContainerFrame::GetContentRect(Environment* ev) const
  467. {
  468.     FW_CRect contentRect = GetBounds(ev);
  469.  
  470.     if (IsRoot(ev))
  471.     {
  472.         FW_CPoint sbSize = FW_CScrollBar::GetDefaultScrollBarSize();
  473.     
  474.         contentRect.bottom -= sbSize.y;
  475.         contentRect.right -= sbSize.x;
  476.     }
  477.     
  478.     return contentRect;
  479. }
  480.  
  481. //----------------------------------------------------------------------------------------
  482. // CContainerFrame::AdjustContentViewSize
  483. //----------------------------------------------------------------------------------------
  484.  
  485. void CContainerFrame::AdjustContentViewSize(Environment* ev, FW_ERedrawVerb redraw)
  486. {
  487.     FW_CRect contentRect = GetContentRect(ev);    
  488.  
  489.     FW_CPoint drawingSize = fContainerPart->GetDrawingSize();
  490.     
  491.     // ----- I need to take into account the zoom factor -----
  492.     drawingSize.x *= fZoomFactor;
  493.     drawingSize.y *= fZoomFactor;
  494.  
  495.     FW_CPoint drawViewSize(FW_Minimum(drawingSize.x, contentRect.Width()),
  496.                             FW_Minimum(drawingSize.y, contentRect.Height()));
  497.  
  498.     FW_CPoint currentSize = GetContentView(ev)->GetSize(ev);
  499.     if (currentSize != drawViewSize)
  500.     {
  501.         GetContentView(ev)->SetSize(ev, drawViewSize, redraw);
  502.     }
  503. }
  504.  
  505. //----------------------------------------------------------------------------------------
  506. // CContainerFrame::Draw
  507. //----------------------------------------------------------------------------------------
  508.  
  509. void CContainerFrame::Draw(Environment* ev, ODFacet* odFacet, ODShape* invalidShape)
  510. {    
  511.     FW_CViewContext vc(ev, this, odFacet, invalidShape);
  512.  
  513.     FW_CSuperView* contentView = GetContentView(ev);
  514.     FW_CRect contentRect = GetContentRect(ev);
  515.     FW_CRect contentBounds = contentView->GetBounds(ev);
  516.     
  517.     // Note: in this container we always have contentRect == contentBounds because the
  518.     //        content view takes up the whole space, so we could remove this Draw method.
  519.     //        We left it to show you what could be done to draw in the frame outside the 
  520.     //        content view (see also the Draw example)
  521.     if (contentRect != contentBounds)
  522.     {
  523.         FW_CAcquiredODShape shape1 = ::FW_NewODShape(ev, contentRect);
  524.         FW_CAcquiredODShape shape2 = ::FW_NewODShape(ev, contentBounds);
  525.         shape1->Subtract(ev, shape2);        
  526.         
  527.         FW_CRegionShape::RenderRegion(vc, shape1, FW_kFill, FW_kRGBLightGray);
  528.             
  529.         contentBounds.Inset(FW_kFixedNeg1, FW_kFixedNeg1);
  530.         FW_CRectShape::RenderRect(vc, contentBounds, FW_kFrame);
  531.     }
  532. }
  533.  
  534. //----------------------------------------------------------------------------------------
  535. // CContainerFrame::DoMouseDownInEmbeddedFrameBorder
  536. //----------------------------------------------------------------------------------------
  537.  
  538. FW_Handled CContainerFrame::DoMouseDownInEmbeddedFrameBorder(Environment* ev, 
  539.                                                         const FW_CBorderMouseEvent& theBorderMouseEvent)
  540. {    
  541.     FW_gClosedHandCursor.Select();
  542.     
  543.     Drag(ev, theBorderMouseEvent);
  544.     
  545.     return FW_kHandled;
  546. }
  547.  
  548. //----------------------------------------------------------------------------------------
  549. // CContainerFrame::DoMouseDownInEmbeddedFrame
  550. //----------------------------------------------------------------------------------------
  551.  
  552. FW_Handled CContainerFrame::DoMouseDownInEmbeddedFrame(Environment* ev, const FW_CEmbeddedMouseEvent& theEmbeddedMouseEvent)
  553. {
  554.     FW_Handled handled = FW_kNotHandled;
  555.     
  556.     if (theEmbeddedMouseEvent.GetNumberOfClicks(ev) > 1)
  557.     {
  558.         OpenSelection(ev);
  559.         handled = FW_kHandled;
  560.     }
  561.     
  562.     return handled;
  563. }
  564.  
  565. //----------------------------------------------------------------------------------------
  566. //    CContainerFrame::NewDragCommand
  567. //----------------------------------------------------------------------------------------
  568.  
  569. FW_CDragCommand* CContainerFrame::NewDragCommand(Environment* ev, FW_CFrame* theFrame, const FW_CMouseEvent& theMouseEvent)
  570. {
  571. FW_UNUSED(theMouseEvent);
  572.     return FW_NEW(CDragCommand, (ev, fContainerPart, theFrame,
  573.                                 fSelection,
  574.                                 FW_kCanUndo));
  575. }
  576.  
  577. //----------------------------------------------------------------------------------------
  578. //    CContainerFrame::NewDropCommand
  579. //----------------------------------------------------------------------------------------
  580.  
  581. FW_CDropCommand* CContainerFrame::NewDropCommand(Environment* ev,
  582.                                             FW_CFrame* frame,
  583.                                             ODDragItemIterator* dropInfo, 
  584.                                             ODFacet* facet, 
  585.                                             const FW_CPoint& dropPoint)
  586. {
  587.     return FW_NEW(CDropCommand, (ev, fContainerPart, frame,
  588.                                 dropInfo, facet, dropPoint,
  589.                                 FW_kCanUndo));
  590. }
  591.  
  592. //----------------------------------------------------------------------------------------
  593. //    CContainerFrame::ExternalizeFrame
  594. //----------------------------------------------------------------------------------------
  595.  
  596. void CContainerFrame::ExternalizeFrame(Environment* ev, ODStorageUnitView* storageUnitView)
  597. {
  598.     FW_CEmbeddingFrame::ExternalizeFrame(ev, storageUnitView);
  599.     
  600.     FW_PStorageUnitSink suSink(ev, storageUnitView);
  601.     FW_CWritableStream stream(suSink);
  602.     
  603.     stream << fZoomFactor;
  604. }
  605.  
  606. //----------------------------------------------------------------------------------------
  607. //    CContainerFrame::InternalizeFrame
  608. //----------------------------------------------------------------------------------------
  609.  
  610. void CContainerFrame::InternalizeFrame(Environment* ev, ODStorageUnitView* storageUnitView)
  611. {
  612.     FW_CEmbeddingFrame::InternalizeFrame(ev, storageUnitView);
  613.  
  614.     FW_PStorageUnitSink suSink(ev, storageUnitView);
  615.     FW_PBufferedSink sink(ev, suSink);
  616.     FW_CReadableStream stream(sink);
  617.     
  618.     stream >> fZoomFactor;
  619. }
  620.  
  621. //----------------------------------------------------------------------------------------
  622. //    CContainerFrame::FocusStateChanged
  623. //----------------------------------------------------------------------------------------
  624.  
  625. void CContainerFrame::FocusStateChanged(Environment* ev, ODTypeToken focus, FW_Boolean newState, ODFrame* newOwner)
  626. {
  627.     FW_CEmbeddingFrame::FocusStateChanged(ev, focus, newState, newOwner);
  628.     
  629.     if (focus == FW_CPart::fgSelectionFocusToken)
  630.     {
  631.     
  632.         // this may be called when we have not facets, if a containing part detatches
  633.         // this without first getting the focus.  In that case, there's no window!
  634.         
  635.         FW_CWindow* wind = GetWindow(ev);
  636.         if (wind && wind->IsActive(ev))
  637.             fSelection->InvalidateSelectionHandles(ev, this);
  638. /*
  639.         //    • If I get the selection focus I redraw the handles only if the window is not active
  640.         //    if the window is active they already have been redrawn by DoActivateEvent
  641.         //    • If I am loosing the selection focus I redraw the handles only if the window is active
  642.         //    if the window is not active they already have been redrawn by DoActivateEvent
  643.         //    The events order is:
  644.         //        - Window 1 deactivated
  645.         //        - Frame 1 lose selection focus
  646.         //        - Frame 2 gain selection focus
  647.         //        - Window 2 activated
  648.         FW_Boolean windowActive = GetWindow(ev)->IsActive(ev);
  649.         FW_Boolean hilite = newState ? !windowActive : windowActive;
  650.         if (hilite)
  651.             fSelection->RenderAllHandles(ev, this);
  652. */
  653.     }
  654. }
  655.  
  656. //----------------------------------------------------------------------------------------
  657. //    CContainerFrame::EmbeddedFrameRequested
  658. //----------------------------------------------------------------------------------------
  659.  
  660. FW_MProxy* CContainerFrame::EmbeddedFrameRequested(Environment *ev,
  661.                                                     FW_MProxy* baseProxy,
  662.                                                     ODFrame* baseFrame,
  663.                                                     ODShape* frameShape,
  664.                                                     ODPart* embeddedPart,
  665.                                                     ODTypeToken viewType,
  666.                                                     ODTypeToken presentation,
  667.                                                     ODID frameGroupID,
  668.                                                     FW_Boolean isOverlaid,
  669.                                                     FW_Boolean isSubFrame)
  670. {
  671. FW_UNUSED(baseFrame);
  672. FW_UNUSED(frameShape);
  673.     FW_CPresentation* myPresentation = GetPresentation(ev);
  674.     
  675.     CProxy* theBaseProxy = (CProxy*)baseProxy;
  676.     FW_CRect embeddedFrameBounds = theBaseProxy->GetBounds(ev);
  677.  
  678.     embeddedFrameBounds.Offset(embeddedFrameBounds.Width(), FW_kFixed0);
  679.     
  680.     CProxy* proxy = new CProxy(ev, embeddedFrameBounds, fContainerPart, viewType);
  681.         
  682.     FW_CRect tempRect(embeddedFrameBounds);
  683.     tempRect.Place(FW_kFixed0, FW_kFixed0);
  684.     FW_CAcquiredODShape aqFrameShape = ::FW_NewODShape(ev, tempRect);
  685.     
  686.     FW_TRY
  687.     {
  688.          proxy->EmbedPart(ev, 
  689.                     myPresentation,
  690.                     embeddedPart,
  691.                     kODFrameObject,
  692.                     aqFrameShape,
  693.                     viewType,
  694.                     presentation,
  695.                     frameGroupID,
  696.                     isOverlaid,
  697.                     isSubFrame);
  698.     }
  699.     FW_CATCH_BEGIN
  700.     FW_CATCH_EVERYTHING () 
  701.     {
  702.         proxy->Release();
  703.         FW_THROW_SAME ();
  704.     }
  705.     FW_CATCH_END
  706.     
  707.     // ----- Now I can add it to my data                
  708.     fContainerPart->AddProxyToPart(ev, proxy);
  709.  
  710.     // AddShapeToPart acquired proxy. Since this function is actually returning
  711.     // an FW_MProxy, which is currently not refcounted, the caller (which is 
  712.     // happens to be a framework method) can't be counted on to release, so we
  713.     // have to do so for it.
  714.     
  715.     proxy->Release();
  716.  
  717.     // ----- Clip the facets -----
  718.     FW_CFacetClipper facetClipper;
  719.     FW_CAcquiredODShape limitShape = ::FW_NewODShape(ev, embeddedFrameBounds);
  720.     facetClipper.Clip(ev, myPresentation, limitShape);
  721.     
  722.     return proxy;
  723. }
  724.